package com.baize.minespace.controller;


import com.baize.minespace.pojo.Notes;
import com.baize.minespace.service.NotesService;
import com.baize.minespace.utils.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * <p>
 * 笔记信息表 前端控制器
 * </p>
 *
 * @author baize
 * @since 2024-04-15
 */
@RestController
@RequestMapping("/notes")
public class NotesController {
    @Autowired
    private NotesService notesService;

    @ApiModelProperty("新增笔记信息表")
    @ApiOperation(value = "新增笔记信息表", notes = "新增笔记信息表")
    @PostMapping("add")
    public Result<Boolean> addNotes(@RequestBody Notes notes){
        return Result.success(notesService.save(notes));
    }

    @ApiModelProperty("删除笔记信息表")
    @ApiOperation(value = "删除笔记信息表", notes = "删除笔记信息表")
    @GetMapping ("delete/{id}")
    public Result<Boolean> deleteNotes(@PathVariable(value = "id") Integer id) {
        return Result.success(notesService.removeById(id));
    }

    @ApiModelProperty("修改笔记信息表")
    @ApiOperation(value = "修改笔记信息表", notes = "修改笔记信息表")
    @PostMapping("update")
    public Result<Boolean> updateNotes(@RequestBody Notes notes) {
        return Result.success(notesService.updateById(notes));
    }

    @ApiModelProperty("查询笔记信息表")
    @GetMapping("select/{id}")
    public Result<Notes> selectNotes(@PathVariable(value = "id") Integer id) {
        return Result.success(notesService.getById(id));
    }

    @ApiModelProperty("分页查询笔记信息表")
    @ApiOperation(value = "分页查询笔记信息表", notes = "分页查询笔记信息表")
    @GetMapping("page/{rows}/{page}")
    public Result<IPage<Notes>> selectNotesPage(
        @PathVariable(value = "rows") Integer rows,
        @PathVariable(value = "page") Integer page,
        @RequestBody Notes notes
    ) {
        return notesService.selectNotesPage(rows, page, notes);
    }
}
